package com.example.demo.controller;


import com.example.demo.entity.User;
import com.example.demo.service.impl.UserServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author agen
 * @since 2020-04-17
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserServiceImpl userService;

    @RequestMapping("/insert")
    public void createTest() {
        System.out.println("createTest---");
        User user = new User();
        user.setName("agen");
        user.setAge(18);
        userService.insertUser(user);
    }

    @RequestMapping("/save")
    public void serviceTest() {
        User user = new User();
        user.setName("agen");
        user.setAge(18);
        userService.serviceSave(user);
    }

    @RequestMapping("/update")
    public void update() {
        log.info("----------------service插入一条记录： save user----------------");
        User user = new User();
        user.setId(2L);
        user.setName("agen2");
        userService.updateById(user);
    }

    @RequestMapping("/select")
    public void selectTest() {
        userService.selectTest();
    }

    @RequestMapping("/page")
    public void pageTest() {
        userService.pageTest();
    }

    @RequestMapping("/selectUserPage")
    public void selectUserPage() {
//        Page<User> page =new Page<>();

//        log.info("userIPage="+userIPage.getRecords().toString());

//        mapper.mySelectMap(Maps.newHashMap("name", "%a")).forEach(System.out::println);

        userService.selectUserPage();
    }
}

